package cn.iocoder.yudao.module.call.framework.client.impl;

import cn.hutool.json.JSONObject;
import cn.iocoder.yudao.module.call.framework.client.CallClient;
import cn.iocoder.yudao.module.call.api.client.dto.*;
import cn.iocoder.yudao.module.call.framework.client.property.CallProperties;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;

@Slf4j
public abstract class AbstractCallClient implements CallClient {

    protected volatile CallProperties properties;


    /**
     * 初始化
     */
    public final void init() {
        doInit();
        log.info("[init][配置({}) 初始化完成]", properties);
    }

    /**
     * 自定义初始化
     */
    protected abstract void doInit();

    public final void refresh(CallProperties properties) {
        // 判断是否更新
        if (properties.equals(this.properties)) {
            return;
        }
        log.info("[refresh][配置({})发生变化，重新初始化]", properties);
        this.properties = prepareProperties(properties);
        // 初始化
        this.init();
    }

    protected CallProperties prepareProperties(CallProperties properties) {
        return properties;
    }

    public AbstractCallClient(CallProperties properties) {
        this.properties = properties;
    }

    @Override
    public Long getId() {
        return properties.getId();
    }

    @Override
    public String getName() {
        return properties.getName();
    }

    @Override
    public String getMode() {
        return properties.getPhoneMode();
    }

    @Override
    public String getCode() {
        return properties.getCode();
    }

    @Override
    public CallRespDTO handleCall(CallReqDTO callReqDTO) {
        return null;
    }

    @Override
    public AgentRespDTO handleAgent(AgentReqDTO agentReqDTO) {
        return null;
    }

    @Override
    public void handleHangup(String callId) {

    }

    @Override
    public CallNotifyDTO handleNotify(JSONObject jsonObject) {
        return null;
    }

    @Override
    public boolean createAgent(AgentReqDTO agentReqDTO) {
        return false;
    }

    @Override
    public void updateAgent(AgentReqDTO agentReqDTO) {
    }

    @Override
    public JSONObject getAccountInfo(String agent) {
        return null;
    }

    @Override
    public Boolean forceLogout(String agentId) {
        return true;
    }

    @Override
    public Boolean forceNotReady(String agentId) {
        return true;
    }

    @Override
    public Boolean forceReady(String agentId) {
        return true;
    }

    @Override
    public Boolean forceSkillChange(String agentId, List<Map<String, Object>> skills) {
        return true;
    }
}
